package com.mz.ozy.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.mz.ozy.R;
import com.mz.ozy.activity.assets.BalanceDetailsActivity;
import com.mz.ozy.activity.assets.JDDetailsActivity;
import com.mz.ozy.activity.assets.QCDetailsActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */

public class AssetsAdapter extends RecyclerView.Adapter<AssetsAdapter.MyViewHolder> {


    private Context mContext;
    private int[] bgs = {R.mipmap.assets_ye_bg_icon, R.mipmap.assets_qc_bg_icon, R.mipmap.assets_jd_bg_icon};
    private int[] icons = {R.mipmap.assets_account_icon_type1, R.mipmap.assets_account_icon_type2, R.mipmap.assets_account_icon_type3};
    private int[] names = {R.string.assets_ye, R.string.assets_qc, R.string.assets_jd};
    List<String> amountList;
    private int isZzOpen = 1;//是否开启转账功能 1开启

    public AssetsAdapter(Context context, List<String> amountList) {
        mContext = context;
        this.amountList = amountList;
        initData();
    }


    public void setIsZzOpen(int isZzOpen) {
        this.isZzOpen = isZzOpen;
    }

    public void initData() {
        amountList.add("0.0000");
        amountList.add("0.0000");
        amountList.add("0.0000");
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_assets, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.ivTypeBg.setImageResource(bgs[position]);
        holder.ivIcon.setImageResource(icons[position]);
        holder.tvAccountType.setText(names[position]);
        holder.tvMoney.setText(amountList.get(position));
        holder.llItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position) {
                    case 0:
                        mContext.startActivity(new Intent(mContext, BalanceDetailsActivity.class));
                        break;
                    case 1:
                        Intent intent = new Intent(mContext, QCDetailsActivity.class);
                        intent.putExtra("isOpen", isZzOpen);
                        mContext.startActivity(intent);
                        break;
                    case 2:
                        intent = new Intent(mContext, JDDetailsActivity.class);
                        intent.putExtra("amount", amountList.get(position));
                        mContext.startActivity(intent);
                        break;
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        return icons.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_type_bg)
        ImageView ivTypeBg;
        @BindView(R.id.iv_icon)
        ImageView ivIcon;
        @BindView(R.id.tv_account_type)
        TextView tvAccountType;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.ll_item)
        FrameLayout llItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }


    }


}
